//
//  Status.swift
//  SinaWeiBo
//
//  Created by 有风 on 16/2/20.
//  Copyright © 2016年 YouFeng. All rights reserved.
//

import UIKit

class Status: NSObject {
    
    var id: Int64 = 0
    
    //微博创建时间
    var created_at: String?
    
    //微博正文
    var text: String?
    
    //微博来源
    var source: String?
    
    //用户
    var user: User?
    
    //如果是原创微博 retweeted_status 不存在
    var retweeted_status: Status?

    //配图视图数组
    var pic_urls: [[String: String]]? {
        didSet {
            guard let urls = pic_urls else{
                return
            }
            
            imageURLs = [NSURL]()
            
            for item in urls {
                let urlString = item["thumbnail_pic"]
                let url = NSURL(string: urlString!)
                
                imageURLs?.append(url!)
            }
            
        }
    }
    
    //
    var imageURLs: [NSURL]?
    
    //使用KVC设置初始值
    init(dict: [String : AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
        
    }
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user"{
            if let dict = value as? [String : AnyObject] {
                user = User(dict : dict)
                return
            }
            
            
        }
        
        if key == "retweeted_status"{
            if let dict = value as? [String : AnyObject] {
                retweeted_status = Status(dict : dict)
                return
            }
            
            
        }

        super.setValue(value, forKey: key)
        
    }
    override func setValue(value: AnyObject?, forUndefinedKey key: String) { }
}
